#include "bh1750.h"
#include "i2c.h"
#include "systick.h"

int init_bh1750()
{
    uint8_t power_on = BH_POWER_ON;
    uint8_t reset = BH_RESET;

    swi2c_write_data(0x46,&power_on,1);
    delay_1ms(10);
    swi2c_write_data(0x46,&reset,1);

    return 0;
}

int get_light_value(uint16_t *light_value)
{
    uint8_t r_light_data[2] = {0};
    uint8_t high_mode = BH_HMODE_RESOLUTION;

    swi2c_write_data(0x46,&high_mode,1);
    delay_1ms(180);
    swi2c_read_data(0x46,r_light_data,2);
       
    *light_value = ((r_light_data[0] << 8) | r_light_data[1]);
    return 0;
}